package org.link.web;

import java.util.ArrayList;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.link.bean.Page;
import org.link.bean.User;
import org.link.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * project_name:oracledemo
 * package_name:org.link.web
 * file_name:UserController.java
 * @author Link
 * create_date:2015年12月24日 下午4:05:09
 * modified_date:
 * description:
 *
 */
@Controller
public class UserController {

	@Resource
	private IUserService userService;
	
	/**
	 * 
	 * description:主页跳转
	 * 2015年12月24日 下午4:07:15
	 * @author Link
	 * @return
	 *
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String index(){
		return "index";
	}
	
	@RequestMapping(value="/addUser",method=RequestMethod.POST)
	public String addUser(User user,HttpServletRequest request){
		userService.addUser(user);
		request.setAttribute("allUser", (ArrayList<User>)userService.selectUserByLimit(new Page(0,5)));
		request.setAttribute("totalPage", userService.selectCount());
		return "index";
	}
	
	@ResponseBody
	@RequestMapping(value="/pageChange",method=RequestMethod.POST)
	public ArrayList<User> pageChange(@RequestBody Page page){//分页查询
		return (ArrayList<User>)userService.selectUserByLimit(page);
	}
	
}







